package com.ly.houses.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ly.houses.common.Login;
import com.ly.houses.mapper.LoginMapper;
import com.ly.houses.model.House;
import com.ly.houses.model.User;
import com.ly.houses.service.HouseService;
import com.ly.houses.service.LoginService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/houseApi")
public class HouseApi {
    @Resource
    private HouseService houseService;
    @Resource
    private LoginMapper loginMapper;

    @GetMapping("/list")
    public List listHouseByBuildingId(@Login User user, Long buildingId) {
        if (user == null) {
            return new ArrayList();
        }
        User isUser=loginMapper.getByOpenId(user.getOpenId());
        if(isUser==null){
            return new ArrayList();
        }
//        PageHelper.startPage(page,pageSize);
        List<House> list = houseService.listHouseByBuildingId(buildingId);
//        PageInfo pageInfo = new PageInfo(list);
        return list;
    }

    @GetMapping("/get")
    public House get(@Login User user, Long houseId) {
        if (user == null) {
            return null;
        }
        User isUser=loginMapper.getByOpenId(user.getOpenId());
        if(isUser==null){
            return null;
        }
//        PageHelper.startPage(page,pageSize);
        House house = houseService.get(houseId);
//        PageInfo pageInfo = new PageInfo(list);
        return house;
    }
}
